//
//  SSKJ_TabbarController.m
//  SSKJ
//
//  Created by 刘小雨 on 2018/12/6.
//  Copyright © 2018年 刘小雨. All rights reserved.
//

#import "SSKJ_TabbarController.h"

#import "UIImage+RoundedRectImage.h"

#import "SSKJ_BaseNavigationController.h"

#import "ViewController.h"

#import "Market_Main_List_ViewController.h"

#import "BBTradeViewController.h"

#import "ContractTrade_ViewController.h"

#import "BFEX_FBC_Index_ViewController.h"

#import "Mine_ViewController.h"

#define kControllerNameArray @[@"Market_Main_List_ViewController",@"BBTradeViewController",@"ContractTrade_ViewController",@"BFEX_FBC_Index_ViewController",@"Mine_ViewController"]

#define kControllerTitleArray @[SSKJLocalized(@"行情", nil),SSKJLocalized(@"币币交易", nil),SSKJLocalized(@"合约交易", nil),SSKJLocalized(@"C2C交易", nil),SSKJLocalized(@"我的", nil)]
#define kImageNameArray @[@"",@"",@"",@"",@""]
#define kSelectedImageNameArray @[@"",@"",@"",@"",@""]

@interface SSKJ_TabbarController ()
@end

@implementation SSKJ_TabbarController
#pragma mark - 改变 tabbar 选中状态下的文字颜色


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 添加所有子控制器
    [self addAllChildViewController];
    [[UITabBar appearance] setBarTintColor:kMainColor];
}

#pragma mark - 加载所有的子控制器
- (void)addAllChildViewController
{
    for (int i = 0; i < kControllerNameArray.count; i++)
    {
        NSString *controllerStr = kControllerNameArray[i];
        NSString *title = kControllerTitleArray[i];
        NSString *image = kImageNameArray[i];
        NSString *selectedImage = kSelectedImageNameArray[i];
        id controller = [[NSClassFromString(controllerStr) alloc] init] ;
        [self addChildVC:controller title:title image:image selectedImage:selectedImage];
    }
    
}

/**
 *  添加子控制器
 *
 *  @param childVC      子控制器
 *  @param title        标题
 *  @param image        正常状态图片
 *  @param seletedImage 选中时的图片
 */
- (void)addChildVC:(UIViewController *)childVC title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)seletedImage
{
    // 添加为tabbar控制器的子控制器
    SSKJ_BaseNavigationController *nav = [[SSKJ_BaseNavigationController alloc] initWithRootViewController:childVC];
    
    // 设置标题
    nav.tabBarItem.title = title;
    
    // 设置未选中图标
    UIImage *normalImage =  [UIImage imageNamed:image];
    nav.tabBarItem.image = [normalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置选中的图标
    UIImage *selectedImage = [UIImage imageNamed:seletedImage];
    // 不要渲染
    nav.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    
    // 设置tabbarItem的普通文字
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = UIColorFromRGB(0x999999);
    textAttrs[NSFontAttributeName] = WLFontSize(12.0);
    [nav.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    
    //设置tabBarItem的选中文字颜色
    NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];
    selectedTextAttrs[NSForegroundColorAttributeName] = kMainTextColor;
    [nav.tabBarItem setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];
    
    
    [self addChildViewController:nav];
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
